package com.redare.dev.smart.generator.service.impl;

import com.redare.dev.smart.generator.sdk.OnlFormFieldSdk;
import com.redare.dev.smart.generator.sdk.pojo.OnlFormField;
import com.redare.dev.smart.generator.sdk.pojo.form.OnlFormFieldForm;
import com.redare.dev.smart.generator.service.service.OnlFormFieldService;
import com.redare.devframework.common.pojo.CommonResult;
import com.redare.devframework.common.pojo.Page;
import com.redare.devframework.common.validation.ValidationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * impl
 *
 * @author yangqiangyu
 * @date 2021-08-28 23:03:12
 */
@Service(value = "com.redare.dev.smart.generator.impl.OnlFormFieldSdkImpl")
public class OnlFormFieldSdkImpl implements OnlFormFieldSdk {

    @Autowired
    OnlFormFieldService onlFormFieldService;

    @Override
    public CommonResult<Boolean> codeGenerate(OnlFormFieldForm.Add form) {
        return null;
    }

    @Override
    public CommonResult<Boolean> addOnlFormField(OnlFormFieldForm.Add form) {
        CommonResult result = ValidationUtils.simpleValidate(form);
        if (result.isNotSuccess()) {
            return result;
        }
        boolean bool = onlFormFieldService.addOnlFormField(form);
        return CommonResult.returnBoolWrapper(bool, "添加失败");
    }

    @Override
    public CommonResult<Boolean> editOnlFormField(OnlFormFieldForm.Edit form) {
        CommonResult result = ValidationUtils.simpleValidate(form);
        if (result.isNotSuccess()) {
            return result;
        }
        boolean bool = onlFormFieldService.editOnlFormField(form);
        return CommonResult.returnBoolWrapper(bool, "编辑失败");
    }

    @Override
    public CommonResult<Boolean> deleteOnlFormField(OnlFormFieldForm.Del form) {
        CommonResult result = ValidationUtils.simpleValidate(form);
        if (result.isNotSuccess()) {
            return result;
        }
        boolean bool = onlFormFieldService.deleteOnlFormField(form);
        return CommonResult.returnBoolWrapper(bool, "删除失败");
    }

    @Override
    public CommonResult<List<OnlFormField>> findOnlFormFieldList(OnlFormFieldForm.Search form) {
        List<OnlFormField> list = onlFormFieldService.findOnlFormFieldList(form);
        return CommonResult.returnSuccessWrapper(list);
    }

    @Override
    public CommonResult<List<OnlFormField>> findOnlFormFieldList(OnlFormFieldForm.Search form, int curPage, int pageSize) {
        List<OnlFormField> list = onlFormFieldService.findOnlFormFieldList(form, curPage, pageSize);
        return CommonResult.returnSuccessWrapper(list);
    }

    @Override
    public CommonResult<Page<OnlFormField>> findOnlFormFieldPage(OnlFormFieldForm.Search form, int curPage, int pageSize) {
        Page<OnlFormField> page = onlFormFieldService.findOnlFormFieldPage(form, curPage, pageSize);
        return CommonResult.returnSuccessWrapper(page);
    }

    @Override
    public CommonResult<OnlFormField> getOnlFormField(OnlFormFieldForm.Get form) {
        CommonResult result = ValidationUtils.simpleValidate(form);
        if (result.isNotSuccess()) {
            return result;
        }
        OnlFormField info = onlFormFieldService.getOnlFormField(form);
        if (info == null) {
            return CommonResult.returnFailsWrapper("数据不存在");
        }
        return CommonResult.returnSuccessWrapper(info);
    }


}

